package com.wd.tw.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wd.tw.domain.entity.ElevatorInfo;
import com.wd.tw.service.ElevatorConfigService;
import com.wd.tw.service.ElevatorInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wd.common.core.controller.BaseController;
import com.wd.common.core.domain.HttpResponse;
import com.wd.common.annotation.Log;
import com.wd.common.enums.BusinessType;
import com.wd.common.utils.poi.ExcelUtil;


/**
 * 电梯信息Controller
 * 
 * @author liumingkun
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/elevator/info")
public class ElevatorInfoController extends BaseController
{
    @Resource
    private ElevatorInfoService elevatorInfoService;

    @Resource
    private ElevatorConfigService configService;

    /**
     * 查询电梯信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:info:list')")
    @GetMapping("/list")
    public HttpResponse list(ElevatorInfo elevatorInfo)
    {
        startPage();
        List<ElevatorInfo> list = elevatorInfoService.selectElevatorInfoList(elevatorInfo);
        HttpResponse httpResponse = HttpResponse.successData(getDataTable(list));
        httpResponse.setCode(0);
        return httpResponse;
    }

    /**
     * 导出电梯信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:info:export')")
    @Log(title = "电梯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElevatorInfo elevatorInfo)
    {
        List<ElevatorInfo> list = elevatorInfoService.selectElevatorInfoList(elevatorInfo);
        ExcelUtil<ElevatorInfo> util = new ExcelUtil<ElevatorInfo>(ElevatorInfo.class);
        util.exportExcel(response, list, "电梯信息数据");
    }

    /**
     * 获取电梯信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:info:query')")
    @GetMapping(value = "/{elevatorId}")
    public HttpResponse getInfo(@PathVariable("elevatorId") Long elevatorId)
    {
        return successData(elevatorInfoService.selectElevatorInfoByElevatorId(elevatorId));
    }

    /**
     * 新增电梯信息
     */
    @PreAuthorize("@ss.hasPermi('business:info:add')")
    @Log(title = "电梯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public HttpResponse add(@RequestBody ElevatorInfo elevatorInfo)
    {
        return getResult(elevatorInfoService.insertElevatorInfo(elevatorInfo));
    }

    /**
     * 修改电梯信息
     */
    @PreAuthorize("@ss.hasPermi('business:info:edit')")
    @Log(title = "电梯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public HttpResponse edit(@RequestBody ElevatorInfo elevatorInfo)
    {
        HttpResponse result = getResult(elevatorInfoService.updateElevatorInfo(elevatorInfo));
        configService.refreshConfig();
        result.setCode(0);
        return result;
    }

    /**
     * 删除电梯信息
     */
    @PreAuthorize("@ss.hasPermi('business:info:remove')")
    @Log(title = "电梯信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{elevatorIds}")
    public HttpResponse remove(@PathVariable Long[] elevatorIds)
    {
        return getResult(elevatorInfoService.deleteElevatorInfoByElevatorIds(elevatorIds));
    }
}
